package com.fh.controller;

import com.fh.common.ResultEnum;
import com.fh.common.ResultMassage;
import com.fh.model.Brand;
import com.fh.service.MallProductService;
import com.fh.util.DataTablePageUtil;
import com.fh.vo.MallBrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author
 * @create 2020-07-15 21:52
 */
@Controller
@RequestMapping("MallProductController")
public class MallProductController {


    @Autowired
    public MallProductService mallProductService;

    @RequestMapping("toShow")
    public String toShow() {

        return "brand/brand-Show";
    }

    @RequestMapping("query")
    @ResponseBody
    public ResultMassage query(DataTablePageUtil<Brand> pageUtil, MallBrandVo vo) {

        try {
            //查询数据,放入message对象中
            DataTablePageUtil<Brand> brandDataTablePageUtil = mallProductService.selectProduct(pageUtil, vo);

            return new ResultMassage(ResultEnum.QUERY_SUCCESS_MSG, brandDataTablePageUtil);
        } catch (Exception e) {
            return new ResultMassage(ResultEnum.QUERY_ERROR_MSG);
        }
    }


    @RequestMapping("add")
    @ResponseBody
    public ResultMassage add(Brand brand) {
        try {
            mallProductService.addBrand(brand);
            return    new ResultMassage(ResultEnum.ADD_SUCCESS_MSG);
        } catch (Exception e) {
            return  new ResultMassage(ResultEnum.ADD_ERROR_MSG);

        }
    }

    @RequestMapping("toUpdate")
    @ResponseBody
    public ResultMassage toUpdate(Integer brandId){
        try {
            //Brand brand=mallProductService.selectId(brandId);
            return  new ResultMassage(ResultEnum.TOUPDATE_SUCCESS_MSG,mallProductService.selectId(brandId));
        }catch (Exception e){
            return new ResultMassage(ResultEnum.TOUPDATE_SUCCESS_MSG);
        }
    }

    @RequestMapping("updateBrand")
    @ResponseBody
    public ResultMassage updateBrand(Brand brand) {
        try {
            mallProductService.updateBrand(brand);
            return new ResultMassage(ResultEnum.UPDATE_SUCCESS_MSG);
        } catch (Exception e) {
            return new ResultMassage(ResultEnum.UPDATE_ERROR_MSG);
        }
    }

    @RequestMapping("deleteBrand")
    @ResponseBody
    public ResultMassage deleteBrand(Integer brandId){
        try {
            mallProductService.deleteBrand(brandId);
            return new ResultMassage(ResultEnum.DELETE_SUCCESS_MSG);
        }catch (Exception e){
            return new ResultMassage(ResultEnum.DELETE_ERROR_MSG);
        }
    }
}